home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / MovingText / MovingText.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  8.4 KB  |  368 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.net.URLEncoder;
  15.  
  16. public class MovingText extends Applet implements Runnable, MouseListener {
  17.    private Thread thread;
  18.    private Image buffer;
  19.    // $FF: renamed from: b java.awt.Graphics
  20.    private Graphics field_0;
  21.    private boolean loaded;
  22.    // $FF: renamed from: wi int
  23.    private int field_1;
  24.    // $FF: renamed from: he int
  25.    private int field_2;
  26.    private int pause = 50;
  27.    // $FF: renamed from: X float
  28.    private float field_3;
  29.    // $FF: renamed from: Y float
  30.    private float field_4;
  31.    private Color backColor;
  32.    private String statusBarText;
  33.    private AudioClip sound;
  34.    private AudioClip clicSound;
  35.    private AudioClip enterSound;
  36.    private boolean loopSound;
  37.    private String link;
  38.    private String text;
  39.    // $FF: renamed from: fm java.awt.FontMetrics
  40.    private FontMetrics field_5;
  41.    private int wiText;
  42.    private int textHeight = 10;
  43.    private Color textColor;
  44.    private Color enterTextColor;
  45.    private float XStep = 3.0F;
  46.  
  47.    public String getAppletInfo() {
  48.       return "Name: MovingText\r\nAuthor: Taiji Software\r\n";
  49.    }
  50.  
  51.    public MovingText() {
  52.       ((Component)this).addMouseListener(this);
  53.    }
  54.  
  55.    public void register() {
  56.       try {
  57.          URL u = new URL("http://www.taijisoftware.com");
  58.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  59.       } catch (Exception e) {
  60.          System.out.println(e);
  61.          this.stop();
  62.       }
  63.    }
  64.  
  65.    public void init() {
  66.       String codeBase = null;
  67.  
  68.       try {
  69.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  70.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  71.          codeBase = codeBase.toUpperCase();
  72.       } catch (Exception var9) {
  73.       }
  74.  
  75.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  76.          String regCode = ((Applet)this).getParameter("registration_code");
  77.          if (regCode == null) {
  78.             regCode = ((Applet)this).getParameter("reg_domain");
  79.             if (regCode == null) {
  80.                this.register();
  81.             } else {
  82.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  83.                   codeBase = "WWW." + codeBase;
  84.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  85.                   codeBase = codeBase.substring(4);
  86.                }
  87.  
  88.                char[] chars = new char[codeBase.length()];
  89.                codeBase.getChars(0, codeBase.length(), chars, 0);
  90.                String key = new String("haricot");
  91.                char[] chars2 = new char[key.length()];
  92.                key.getChars(0, key.length(), chars2, 0);
  93.  
  94.                for(int i = 0; i < codeBase.length(); ++i) {
  95.                   int j;
  96.                   if (i >= key.length()) {
  97.                      j = i - key.length() * (i / key.length());
  98.                   } else {
  99.                      j = i;
  100.                   }
  101.  
  102.                   chars[i] += chars2[j];
  103.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  104.                }
  105.  
  106.                String res = new String(chars);
  107.                if (!res.equalsIgnoreCase(regCode)) {
  108.                   this.register();
  109.                }
  110.             }
  111.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  112.             this.register();
  113.          }
  114.       }
  115.  
  116.       this.getParameters();
  117.       if (this.sound != null) {
  118.          if (this.loopSound) {
  119.             this.sound.loop();
  120.             return;
  121.          }
  122.  
  123.          this.sound.play();
  124.       }
  125.  
  126.    }
  127.  
  128.    public void getParameters() {
  129.       this.field_1 = ((Component)this).getSize().width;
  130.       this.field_2 = ((Component)this).getSize().height;
  131.       this.text = ((Applet)this).getParameter("text");
  132.       String s = ((Applet)this).getParameter("pause");
  133.       if (s != null) {
  134.          this.pause = Integer.parseInt(s);
  135.       }
  136.  
  137.       s = ((Applet)this).getParameter("text_step");
  138.       if (s != null) {
  139.          this.XStep = (float)Integer.parseInt(s);
  140.       }
  141.  
  142.       ((Component)this).setBackground(this.getColor("background_color"));
  143.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  144.       s = ((Applet)this).getParameter("sound_name");
  145.       if (s != null) {
  146.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  147.       }
  148.  
  149.       s = ((Applet)this).getParameter("loop_sound");
  150.       if (s != null) {
  151.          if (s.equals("yes")) {
  152.             this.loopSound = true;
  153.          } else {
  154.             this.loopSound = false;
  155.          }
  156.       }
  157.  
  158.       s = ((Applet)this).getParameter("clic_sound_name");
  159.       if (s != null) {
  160.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  161.       }
  162.  
  163.       s = ((Applet)this).getParameter("enter_sound_name");
  164.       if (s != null) {
  165.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  166.       }
  167.  
  168.       this.link = ((Applet)this).getParameter("link");
  169.       s = ((Applet)this).getParameter("text_height");
  170.       if (s != null) {
  171.          this.textHeight = Integer.parseInt(s);
  172.       }
  173.  
  174.       this.textColor = this.getColor("text_color");
  175.       if (this.textColor == null) {
  176.          this.textColor = Color.white;
  177.       }
  178.  
  179.       this.enterTextColor = this.getColor("enter_text_color");
  180.    }
  181.  
  182.    public Color getColor(String param) {
  183.       String s = ((Applet)this).getParameter(param);
  184.       if (s != null) {
  185.          if (s.substring(0, 1).equals("#")) {
  186.             s = s.substring(1);
  187.             int i = Integer.parseInt(s, 16);
  188.             return new Color(i);
  189.          } else {
  190.             return null;
  191.          }
  192.       } else {
  193.          return null;
  194.       }
  195.    }
  196.  
  197.    public final synchronized void paint(Graphics g) {
  198.       if (this.loaded) {
  199.          this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  200.          this.field_0.drawString(this.text, (int)this.field_3, (int)this.field_4);
  201.          g.drawImage(this.buffer, 0, 0, this);
  202.       }
  203.    }
  204.  
  205.    public final void update(Graphics g) {
  206.       this.paint(g);
  207.    }
  208.  
  209.    public void start() {
  210.       if (this.thread == null) {
  211.          this.thread = new Thread(this);
  212.          this.thread.start();
  213.       }
  214.  
  215.    }
  216.  
  217.    public void stop() {
  218.       if (this.thread != null) {
  219.          this.thread = null;
  220.       }
  221.  
  222.       if (this.sound != null) {
  223.          this.sound.stop();
  224.       }
  225.  
  226.    }
  227.  
  228.    public void run() {
  229.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  230.       this.field_0 = this.buffer.getGraphics();
  231.       this.field_0.setColor(this.textColor);
  232.       Font normalFont = this.field_0.getFont();
  233.       String fontName = ((Applet)this).getParameter("text_font_name");
  234.       if (fontName == null) {
  235.          fontName = normalFont.getName();
  236.       }
  237.  
  238.       int style = 0;
  239.       String s = ((Applet)this).getParameter("text_font_style");
  240.       if (s != null) {
  241.          if (s.equals("bold")) {
  242.             style = 1;
  243.          } else if (s.equals("italic")) {
  244.             style = 2;
  245.          } else if (s.equals("bold_italic")) {
  246.             style = 3;
  247.          } else {
  248.             style = 0;
  249.          }
  250.       }
  251.  
  252.       try {
  253.          normalFont = new Font(fontName, style, this.textHeight);
  254.       } catch (Exception var9) {
  255.          normalFont = new Font(fontName, style, this.textHeight);
  256.       }
  257.  
  258.       this.field_0.setFont(normalFont);
  259.       this.field_5 = this.field_0.getFontMetrics();
  260.       this.wiText = this.field_5.stringWidth(this.text);
  261.       int descent = this.field_5.getDescent();
  262.       int heText = this.field_5.getAscent();
  263.       this.field_3 = (float)((this.field_1 - this.wiText) / 2);
  264.       this.field_3 = 0.0F;
  265.       this.field_4 = (float)(this.field_2 / 2);
  266.       this.loaded = true;
  267.       float YStep = this.XStep;
  268.  
  269.       while(true) {
  270.          ((Component)this).repaint();
  271.          this.field_3 += this.XStep;
  272.          this.field_4 += YStep;
  273.          if (this.field_3 > (float)(this.field_1 - this.wiText) || this.field_3 < 0.0F) {
  274.             this.XStep = -(this.XStep - ((float)Math.random() - 0.5F) / 2.0F);
  275.          }
  276.  
  277.          if (this.field_4 >= (float)(this.field_2 - descent) || this.field_4 <= (float)heText) {
  278.             YStep = -(YStep - ((float)Math.random() - 0.5F) / 2.0F);
  279.          }
  280.  
  281.          try {
  282.             Thread.sleep((long)this.pause);
  283.          } catch (InterruptedException var8) {
  284.             this.stop();
  285.          }
  286.       }
  287.    }
  288.  
  289.    public URL giveURL(String url) {
  290.       try {
  291.          if (url.toUpperCase().startsWith("HTTP")) {
  292.             return new URL(url);
  293.          } else if (url.toUpperCase().startsWith("FTP")) {
  294.             int p = url.indexOf(":");
  295.             int p2 = url.indexOf(":", p + 1);
  296.             if (p2 != -1) {
  297.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  298.             }
  299.  
  300.             p = url.indexOf("%40");
  301.             if (p != -1) {
  302.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  303.             }
  304.  
  305.             return new URL(url);
  306.          } else {
  307.             return new URL(((Applet)this).getCodeBase(), url);
  308.          }
  309.       } catch (MalformedURLException e) {
  310.          System.out.println(e);
  311.          return null;
  312.       }
  313.    }
  314.  
  315.    public void mouseClicked(MouseEvent e) {
  316.    }
  317.  
  318.    public void mouseEntered(MouseEvent e) {
  319.       if (this.enterTextColor != null) {
  320.          this.field_0.setColor(this.enterTextColor);
  321.       }
  322.  
  323.       if (this.statusBarText != null) {
  324.          ((Applet)this).showStatus(this.statusBarText);
  325.       }
  326.  
  327.       if (this.enterSound != null) {
  328.          this.enterSound.play();
  329.       }
  330.  
  331.       if (this.link != null) {
  332.          ((Component)this).setCursor(new Cursor(12));
  333.       }
  334.  
  335.    }
  336.  
  337.    public void mouseExited(MouseEvent e) {
  338.       if (this.enterTextColor != null) {
  339.          this.field_0.setColor(this.textColor);
  340.       }
  341.  
  342.       if (this.link != null) {
  343.          ((Component)this).setCursor(new Cursor(0));
  344.       }
  345.  
  346.    }
  347.  
  348.    public void mousePressed(MouseEvent e) {
  349.       if (this.clicSound != null) {
  350.          this.clicSound.play();
  351.       }
  352.  
  353.       if (this.link != null) {
  354.          String target = ((Applet)this).getParameter("target");
  355.          if (target == null) {
  356.             target = "_blank";
  357.          }
  358.  
  359.          URL u = this.giveURL(this.link);
  360.          ((Applet)this).getAppletContext().showDocument(u, target);
  361.       }
  362.  
  363.    }
  364.  
  365.    public void mouseReleased(MouseEvent e) {
  366.    }
  367. }
  368.